package pers.mingshan.thread;

/**
 * @author hanjuntao
 * @date 2025/1/10 0010
 */
public class ThreadTest {

    public static void main(String[] args) throws InterruptedException {
        System.out.println("主线程开始运行,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
        ThreadDemo threadDemoOne = new ThreadDemo();
        threadDemoOne.start();
        //join 强占 cpu
        threadDemoOne.join();
        System.out.println("主线程结束运行,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
    }

    static class ThreadDemo extends Thread {


        public ThreadDemo() {
        }

        @Override
        public void run() {
            System.out.println("当前线程准备进入休眠,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
            try {
                //休眠 2 秒
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("当前线程休眠结束,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
        }
    }

}
